﻿using AccustomeAttributedll;
using AixCommInfo;
using AviewMotionUI.MachineLife;
using ISaveReaddll;
using SaveReaddll;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FinalTestMachine.Motion
{
    public class OtherParamHelper
    {
        #region 创建对象

        public static OtherParamHelper Cur = new OtherParamHelper();

        private OtherParamHelper()
        {
            saveRead = new SaveReadHeler(() => System.IO.Path.Combine(System.Environment.CurrentDirectory, "SysCfg", "SystemConfig.ini"), () => this);
            Read();
            //saveRead = new SaveReadHeler(() => ParamPath_Motion.CurFileFullPath, () => this);
        }

        public static OtherParamHelper CreateInstrance()
        {
            return Cur;
        }

        private SaveReadHeler saveRead;

        #endregion 创建对象

        #region 变量

        /// <summary>
        /// MES工位名称
        /// </summary>
        [SaveRemark]
        [TextBoxRemark("MES工位名称")]
        public ParamObjectText<string> MESStationName = new ParamObjectText<string>() { GetValue = "" };

        [SaveRemark]
        [TextBoxRemark("蜂鸣器器响应时间(ms)")]
        public ParamStructText<int> BuzzerActionTime = new ParamStructText<int>();

        [SaveRemark]
        [TextBoxRemark("电流检查时电压值")]
        public ParamStructText<double> CheckVol = new ParamStructText<double>() { GetValue = 5.5 };

        [SaveRemark]
        [TextBoxRemark("测试时电压值")]
        public ParamStructText<double> TestVol = new ParamStructText<double>() { GetValue = 6.5 };

        [SaveRemark]
        [TextBoxRemark("电压改变延时(ms)")]
        public ParamStructText<int> ChangeVolDelayTime = new ParamStructText<int>() { GetValue = 500 };

        [SaveRemark]
        [TextBoxRemark("连续不良报警数")]
        public ParamStructText<int> ErrContinueNum = new ParamStructText<int>();

        [SaveRemark]
        [TextBoxRemark("测试超时时间(s)")]
        public ParamStructText<int> TestOutTime = new ParamStructText<int>();

        [SaveRemark]
        [TextBoxRemark("NG料盒最大数")]
        public ParamStructText<int> NgBoxMaxNum = new ParamStructText<int>();

        [SaveRemark]
        [TextBoxRemark("NG料盒锁定延时(ms)")]
        public ParamStructText<int> NgBoxDelayTime = new ParamStructText<int>() { GetValue = 200 };

        [SaveRemark]
        [TextBoxRemark("采集卡上电延时(ms)")]
        public ParamStructText<int> CardPowerOnDelayTime = new ParamStructText<int>() { GetValue = 200 };

        /// <summary>
        /// 标定采图超时时间
        /// </summary>
        [SaveRemark]
        [TextBoxRemark("终检图片格式")]
        public ParamObjectText<string> FinalTestImageFormat = new ParamObjectText<string>() { GetValue = "bmp" };


        /// <summary>
        /// 斑马打印机txt名称
        /// </summary>
        [SaveRemark]
        [TextBoxRemark("打印机OK产品txt文件名称(OMS前)")]
        public ParamObjectText<string> ZebraTxtFileName_Front = new ParamObjectText<string>();

        /// <summary>
        /// 斑马打印机txt名称
        /// </summary>
        [SaveRemark]
        [TextBoxRemark("打印机OK产品txt文件名称(OMS左)")]
        public ParamObjectText<string> ZebraTxtFileName_Left = new ParamObjectText<string>();


        /// <summary>
        /// 斑马打印机txt名称
        /// </summary>
        [SaveRemark]
        [TextBoxRemark("打印机OK产品txt文件名称(OMS右)")]
        public ParamObjectText<string> ZebraTxtFileName_Right = new ParamObjectText<string>();

        /// <summary>
        /// 斑马打印机txt名称
        /// </summary>
        [SaveRemark]
        [TextBoxRemark("打印机OK产品txt文件名称(DMS)")]
        public ParamObjectText<string> ZebraTxtFileName_DMS = new ParamObjectText<string>();



        /// <summary>
        /// 斑马打印机txt名称
        /// </summary>
        [SaveRemark]
        [TextBoxRemark("打印机NG产品txt文件名称")]
        public ParamObjectText<string> ZebraTxtNGFileName = new ParamObjectText<string>();

        [SaveRemark]
        [TextBoxRemark("扫码成功后双启动灯闪烁时间（ms）")]
        public ParamObjectText<int> twinkleTotalTime = new ParamObjectText<int> { GetValue = 3000 };

        [SaveRemark]
        [TextBoxRemark("扫码成功后双启动灯闪烁间隔（ms）")]
        public ParamObjectText<int> twinkleInterval = new ParamObjectText<int> { GetValue = 200 };

        [SaveRemark]
        [TextBoxRemark("扫码后需检测的前缀")]
        public ParamObjectText<string> SnPrefix = new ParamObjectText<string>();

        [SaveRemark]
        [TextBoxRemark("Mes工位名称")]
        public ParamObjectText<string> MesStationName = new ParamObjectText<string>();


        /// <summary>
        /// 工位1_NG数
        /// </summary>
        [SaveRemark]
        public ParamObjectText<int> Station1_NGNum = new ParamObjectText<int>() { GetValue = 0 };

        /// <summary>
        /// 工位2_NG数
        /// </summary>
        [SaveRemark]
        public ParamObjectText<int> Station2_NGNum = new ParamObjectText<int>() { GetValue = 0 };

        /// <summary>
        /// 工位3_NG数
        /// </summary>
        [SaveRemark]
        public ParamObjectText<int> Station3_NGNum = new ParamObjectText<int>() { GetValue = 0 };

        /// <summary>
        /// 工位4_NG数
        /// </summary>
        [SaveRemark]
        public ParamObjectText<int> Station4_NGNum = new ParamObjectText<int>() { GetValue = 0 };

        //[SaveRemark]
        //[TextBoxRemark("探针上顶次数最大值")]
        ///// <summary>
        ///// NG 探针上顶次数最大值
        ///// </summary>
        //public ParamStructText<int> PinLoadCountMaxValue = new ParamStructText<int>();

        //[SaveRemark]
        //[TextBoxRemark("探针上顶次数预警值")]
        ///// <summary>
        ///// NG 探针上顶次数预警值
        ///// </summary>
        //public ParamStructText<int> PinLoadCountAlarmValue = new ParamStructText<int>();

        #endregion 变量

        public const string TYPE_COMPONENT_PROBE = "探针统计";

        

        public bool CheckXProbe(string x)
        {
            if (MachineLifeVariableManger.Current.CheckComponentCount(TYPE_COMPONENT_PROBE, x.ToUpper() + "治具探针"))
            {
                return false;
            }
            return true;
        }

        public void Initial()
        {
            //设置蜂鸣器响应的时间
            StaticInitial.Motion.LightSwitch.SetBuzzerActionTime(() => BuzzerActionTime.GetValue);
        }

        public void Save()
        {
            saveRead.Save();
        }

        public void Read()
        {
            saveRead.Read();
        }
    }
}